package server.buscador;

import java.awt.geom.Point2D;

import editor.modelo.LandMark;
import editor.modelo.Portal;
import editor.modelo.Portal.Tipo;
import editor.modelo.Space;

/**
 * Es lo mismo que un portal, solo que tiene lo necesario
 * @author Alejandro
 *
 */
public class NodeEdge {

	protected Space target;
	protected Point2D ptoSource;
	protected Point2D ptoTarget;
	public Point2D getPtoTarget() {
		return ptoTarget;
	}

	public void setPtoTarget(Point2D ptoTarget) {
		this.ptoTarget = ptoTarget;
	}

	protected Tipo tipo;
	//protected Clase clase;

	public NodeEdge(Portal p){
		this.target = p.getTarget();
		this.ptoSource = midPointSource(p);
		this.ptoTarget = midPointTarget(p);
		this.tipo = p.getTipo();
		//this.clase = p.getClase();
	}
	
	public NodeEdge(SpaceNode trg, SpaceNode src){
		this.target = trg;
		this.ptoSource = src.getCentro();
		this.ptoTarget = target.getCentro();
		this.tipo = Portal.Tipo.implicit;
	}

	/*
	public NodeEdge(Space target, Point2D pto, Point2D pto2){
		this.target = target;

		this.ptoSource = new Point2D.Float((float)((pto.getX()+pto2.getX())/2),
				(float)((pto.getY()+pto2.getY())/2));
	}*/

	public Tipo getTipo() {
		return tipo;
	}

	public void setTipo(Tipo tipo) {
		this.tipo = tipo;
	}

	public Space getTarget() {
		return target;
	}

	public Point2D getPosition() {
		return ptoSource;
	}


	private Point2D midPointSource(Portal p) {
		Point2D pto = p.getPtoSource();
		Point2D pto2 = p.getSource().getNextPoint(pto);
		return new Point2D.Float((float)((pto.getX()+pto2.getX())/2),
				(float)((pto.getY()+pto2.getY())/2));
	}	

	private Point2D midPointTarget(Portal p) {
		if(p.getTarget() == null) return null;
		Point2D pto = p.getPtoTarget();
		Point2D pto2 = p.getTarget().getNextPoint(pto);
		return new Point2D.Float((float)((pto.getX()+pto2.getX())/2),
				(float)((pto.getY()+pto2.getY())/2));
		//	p.

	}

}
